package org.hsieh.tr.explore.ui.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.hsieh.tr.explore.dbsource.DatabaseInfoManager;
import org.hsieh.tr.explore.dbsource.IDatabaseInfo;
import org.hsieh.tr.explore.ui.DatabaseViewer;
import org.hsieh.tr.explore.ui.NewConnectionWizard;

public class AddConnectionAction implements IViewActionDelegate {

    private DatabaseViewer viewer = null;

    public void init(IViewPart view) {
	viewer = (DatabaseViewer) view;
    }

    public void run(IAction action) {
	NewConnectionWizard wizard = new NewConnectionWizard();
	WizardDialog dialog = new WizardDialog(viewer.getSite().getShell(),
		wizard);
	if (dialog.open() == Dialog.OK) {
	    IDatabaseInfo info = wizard.getInfo();
	    if (info != null) {
		DatabaseInfoManager.INSTANCE.addDatabaseInfo(info);
		viewer.refresh();
	    }
	}
    }

    public void selectionChanged(IAction action, ISelection selection) {

    }

}
